package day12_coll.demo08_comparable;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        Student zs = new Student("张三", 50, 80);
        Student ls = new Student("李四", 55, 90);
        Student ww = new Student("王五", 60, 70);
        Student zl = new Student("赵六", 60, 90);
        TreeSet<Student> students = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int sum=(o2.getSum1()+o2.getSum2())-(o1.getSum1()+o1.getSum2());
                int i=(sum==0)?o1.getName().compareTo(o2.getName()):sum;
                return i;
            }
        });
        students.add(zs);
        students.add(ls);
        students.add(ww);
        students.add(zl);
        for (Student student : students) {
            System.out.println(student.getName());
        }
    }
}
